<template>
  <div class="app">
    <myNavbar :title="headerTitle"></myNavbar>
    <tabbar ref="reflectName" class="tabbar" tabType="bottom" @pageSelected="pageSelected" tabHeight="110"
            tabSlideSwitch="false"
            tabPageAnimated="false" :tabPages="tabPages"></tabbar>
  </div>
</template>

<style>
.app {
  flex: 1
}

.tabbar {
  flex: 1;
  width: 750px;
}
</style>

<script>
import myNavbar from "../components/myNavbar/myNavbar";
import {
  accessToken
} from '@/api/user'
export default {
  name: 'index',
  data() {
    return {
      tabPages: [{
        title: '第一',
        unSelectedIcon: "https://rzico.oss-cn-shenzhen.aliyuncs.com/dinner/Tab/WechatIMG26.png",
        selectedIcon: 'https://rzico.oss-cn-shenzhen.aliyuncs.com/dinner/Tab/WechatIMG25.png',
        url: 'tabs/one',
        tabName: 'index'
      },
        {
          title: '第二',
          unSelectedIcon: "https://rzico.oss-cn-shenzhen.aliyuncs.com/dinner/Tab/Tab-xiaoxi-gray.png",
          selectedIcon: 'https://rzico.oss-cn-shenzhen.aliyuncs.com/dinner/Tab/Tab-xiaoxi-red.png',
          url: 'tabs/two',
          tabName: 'message'
        },
        {
          title: '第三',
          unSelectedIcon: "https://rzico.oss-cn-shenzhen.aliyuncs.com/dinner/Tab/Tab-guanli-gray.png",
          selectedIcon: 'https://rzico.oss-cn-shenzhen.aliyuncs.com/dinner/Tab/Tab-guanli-red.png',
          url: 'tabs/three',
        },
        {
          title: '第四',
          unSelectedIcon: "https://rzico.oss-cn-shenzhen.aliyuncs.com/dinner/Tab/Tab-jingying-gray.png",
          selectedIcon: 'https://rzico.oss-cn-shenzhen.aliyuncs.com/dinner/Tab/Tab-jingying-red.png',
          url: 'tabs/four',
        },
        {
          title: '第五',
          unSelectedIcon: "https://rzico.oss-cn-shenzhen.aliyuncs.com/dinner/Tab/Tab-wode-gray.png",
          selectedIcon: 'https://rzico.oss-cn-shenzhen.aliyuncs.com/dinner/Tab/Tab-wode-red.png',
          url: 'tabs/five',
        },
      ],
      headerTitle:'第一',
      imeiId:''
    }
  },
  mounted() {
    this.imeiId = eeui.getImei()
    this.initIconFont()
    this.accessTokenClick()
  },
  pageResume: function (data) {
    if (this.getGlobalData().token != null){
      this.summaryClick()
    }
  },
  components:{
    myNavbar
  },
  methods: {
    pageSelected(params) {
      console.log(params)
      if (params.position == 0){
        this.headerTitle = '第一'
      }else if (params.position == 1){
        this.headerTitle = '第二'
      }else if (params.position == 2){
        this.headerTitle = '第三'
      }else if (params.position == 3){
        this.headerTitle = '第四'
      }else if (params.position == 4){
        this.headerTitle = '第五'
      }
    },
    accessTokenClick() {
      var _this = this
      storage.getItem("globalData", function (e) {
        if (e.result == "success" && e.data != undefined && e.data != 'undefined') {
          if (!_this.isEmptyString(e.data)) {
            _this.globalData = JSON.parse(e.data);
            let dataStr = JSON.stringify(_this.globalData);
            eeui.setVariate("globalData", dataStr)
          }
        }
        if (_this.getGlobalData().token != null) {
          accessToken({
            token: _this.getGlobalData().token,
            imeiId: _this.imeiId
          }).then(res => {
            if (res.type == 'success') {
              _this.globalData.token = res.data.token;
              _this.globalData.userInfo = res.data.userInfo;
              _this.setGlobalData(_this.globalData);
            } else if (res.type == 'logout') {
              _this.globalData.token = null;
              _this.setGlobalData(_this.globalData)
            }
          }).catch(error => {
          })
        } else {
          _this.globalData.token = null;
          _this.setGlobalData(_this.globalData)
        }
      })
    },
  }
};
</script>
